package com.example.manage.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.example.api.order.ProductOrder;
import com.example.api.pay.PayOrder;
import com.example.api.user.User;
import com.example.manage.client.OrderClient;
import com.example.manage.client.PayClient;
import com.example.manage.client.RepositoryClient;
import com.example.manage.client.UserClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 86188
 */
@RestController
@RequestMapping("/back")
public class BusinessController {
    @Autowired
    private UserClient userClient;

    @Autowired
    private OrderClient orderClient;

    @Autowired
    private RepositoryClient repositoryClient;

    @Autowired
    private PayClient payClient;

    @RequestMapping(value = "/create")
    public String produceOrder() {
        User user = userClient.createUserByPhone("13812345678");
        System.out.println(user);

        ProductOrder order = new ProductOrder();
        order.setId("12345667");
        order.setMoney(100.00);
        order.setProductId("1111");
        order.setNum(66);
        ProductOrder order1 = orderClient.createOrder(order);
        System.out.println(order1);

        Boolean aBoolean = repositoryClient.reduceProduct();
        System.out.println(aBoolean);

        PayOrder payOrder = payClient.createPayOrder();
        System.out.println(payOrder);
        List list = new ArrayList();
        list.add(user);
        list.add(order);
        list.add(aBoolean);
        list.add(payOrder);
        return JSON.toJSONString(list, SerializerFeature.PrettyFormat);
    }
}
